package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @author 32338
 * @date 2024-04-21 11:34:12
 * @description 订单数据层
 */
@Mapper
public interface OrderMapper {
    /**
     * @description
     ***:插入订单数据
     **/
    void insert(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * @description
     ***:根据用户id查询订单
     **/
    @Select("select * from orders where user_id = #{userId}")
    Orders getByUserId(Long userId);

    /**
     * @description
     ***:根据订单状态和订单时间查询订单
     **/
    @Select("select * from orders where status = #{status} and order_time < #{orderTime} ")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);

    /**
     * @description
     ***:条件查询
     **/
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * @description
     ***:根据订单id查询订单
     **/
    @Select("select *from orders where id = #{id}")
    Orders getById(Long id);

    /**
     * @description
     ***:根据状态统计数据
     **/
    @Select("select count(id)from orders where status = #{status}")
    Integer countStatus(Integer status);

    /**
     * @description
     ***:根据动态条件统计营业数据
     **/
    Double sumByMap(Map map);

    /**
     * @description
     ***:根据动态条件统计订单数据
     **/
    Integer countByMap(Map map);

    /**
     * @description
     ***:统计指定时间内销量排名前十
     **/
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin,LocalDateTime end);
}
